<template>
	<view>
		<view class="ag-topbg"></view>
		<view v-for="(MsgModult, index) in MsgList" :key="index">
			<view v-for="(MsgItem, Msgindex) in MsgModult" :key="index" style="margin-top: 40rpx;">
				<view class="TimeLine">
					<view class="TimeLine__tagg">
						<text>{{MsgItem.MsgDate}}</text>
					</view>
				</view>
				<view class="product-item">
					<view class="product-item__info">
						<view class="product-item__head">
							<text class="product-item__title">{{MsgItem.Title}}</text>
							<navigator :url="'../../pages/wodetail/index?orderDetailId='+MsgItem.RelateUri">
								<view class="product-item__tag">
									{{MsgItem.RegardingText}}
								</view>
							</navigator>
						</view>
						<text class="product-item__content">
							{{MsgItem.MsgContent}}
						</text>
						<!-- <view class="product-item__footer">
						<view class="product-item__fitting">4-24 16:43</view>
					</view> -->
					</view>
				</view>
			</view>
		</view>
		<view v-if="IsShowMsg" style="text-align: center;">{{ErrorMsg}}</view>
		<view v-if="IsShowLoadMore" class="loadmore" @click="onLoadMore">
			<text>加载更多</text>
		</view>
	</view>
</template>
<script>
	import Utils from '../../common/utils';
	export default {
		components: {

		},
		data() {
			return {
				pageNum: 1,
				pageSize: 10,
				ErrorMsg: "",
				IsShowMsg: false,
				IsShowLoadMore: false,
				MsgList: [],
				WoId: "",
			}
		},
		onLoad(e) {
			this.GetMsgList();
		},
		onPullDownRefresh() {
			uni.showLoading({
				mask: true,
				title: "加载中.."
			});
			this.pageNum = 0,
				this.MsgList = [];
			this.GetMsgList().then((scc) => {
				uni.hideLoading();
			}, (err) => {
				uni.hideLoading();
			})
		},
		methods: {
			async GetMsgList() {
				let result = await this.testService.GetMsgList(this.UserInfo.mobile, this.pageNum, this.pageSize,
					this.UserInfo.RetId);
				if (result && result.RetBool) {
					if (result.RetObject) {
						let data = JSON.parse(result.RetObject);
						for (let index in data) {
							let item = data[index];
							let UrlJson = this.htmlDecode(item.RelateUri);
							debugger;
							UrlJson = UrlJson.replace(/'/g, "\"");
							let Urlobj = JSON.parse(UrlJson);
							item.RelateUri = Urlobj.paraWOId
							let times = this.getDate(item.MsgDate);
							item.MsgDate = times.titleTime;
						}
						this.MsgList.push(data);
						this.IsShowLoadMore = true;
					} else {
						this.IsShowLoadMore = false;
					}
					if (this.MsgList.length == 0) {
						this.IsShowMsg = true;
						this.ErrorMsg = "暂无消息"
					}
				} else {
					this.IsShowLoadMore = false;
					this.IsShowMsg = true;
					let msg = result.RetMsg ? result.RetMsg : "";
					this.ErrorMsg = "获取消息列表异常！" + msg;
				}

			},
			onLoadMore(e) {
				uni.showLoading({
					mask: true,
					title: "加载中.."
				});
				this.pageNum += 1,
					this.GetMsgList().then((scc) => {
						uni.hideLoading();
					}, (err) => {
						uni.hideLoading();
					})
			},
			htmlDecode(str) {
				let s = "";
				if (str.length == 0) return "";
				s = str.replace(/&gt;/g, "&");
				s = s.replace(/&lt;/g, "<");
				s = s.replace(/&gt;/g, ">");
				s = s.replace(/&nbsp;/g, " ");
				s = s.replace(/&#39;/g, "\'");
				s = s.replace(/&quot;/g, "\"");
				s = s.replace(/<br>/g, "\n");
				return s;
			},
			getDate(msgDate) {
				var msgDateSubTitle = "";
				var msgDateTopTag = "";
				if (msgDate) {
					var dateMsgTemp = new Date(msgDate);
					var currentDate = new Date();
					var strCurrYear = currentDate.getFullYear();
					var strCurrMonth = currentDate.getMonth() + 1;
					var strCurrDay = currentDate.getDate();
					var strCurrHours = currentDate.getHours();
					var strMsgYear = dateMsgTemp.getFullYear();
					var strMsgMonth = dateMsgTemp.getMonth() + 1;
					var strMsgDay = dateMsgTemp.getDate();
					var strMsgHours = dateMsgTemp.getHours();
					var strMsgMinutes = dateMsgTemp.getMinutes();
					if (strMsgMinutes.toString().length == 1) {
						strMsgMinutes = "0" + strMsgMinutes;
					}
					if (strCurrYear == strMsgYear && strCurrMonth == strMsgMonth && strCurrDay == strMsgDay) {
						msgDateTopTag = strMsgHours + ":" + strMsgMinutes;
						msgDateSubTitle = strMsgMonth + "月" + strMsgDay + "日";
					} else if (strCurrYear == strMsgYear && strCurrMonth == strMsgMonth && strCurrDay - 1 == strMsgDay) {
						msgDateTopTag = "昨天 " + strMsgHours + ":" + strMsgMinutes;
						msgDateSubTitle = strMsgMonth + "月" + strMsgDay + "日";
					} else if (strCurrYear == strMsgYear) {
						msgDateTopTag = strMsgMonth + "月" + strMsgDay + "日 " + strMsgHours + ":" + strMsgMinutes;
						msgDateSubTitle = strMsgMonth + "月" + strMsgDay + "日";
					} else {
						msgDateTopTag = strMsgYear + "年" + strMsgMonth + "月" + strMsgDay + "日 " + strMsgHours + ":" + strMsgMinutes;
						msgDateSubTitle = strMsgYear + "年" + strMsgMonth + "月" + strMsgDay + "日";
					}
				}
				return {
					titleTime:msgDateTopTag,
					subTime:msgDateSubTitle,
				}
			},
		},
	}
</script>

<style lang="scss">
	@import './index.scss';
</style>
